//
//  UIBarButtonItem+Extension.swift
//  WeiBo
//
//  Created by AaronWei on 2017/6/4.
//  Copyright © 2017年 AaronWei. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title: String, imageName: String? = nil, target: Any?, action: Selector) {
        
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        if imageName != nil {
            
            button.setImage(UIImage(named: imageName!), for: .normal)
            
            button.setImage(UIImage(named: "\(imageName!)_highlighted"), for: .highlighted)
            
        }
        
        button.setTitle(title, for: .normal)
        
        button.setTitleColor(UIColor.gray, for: .normal)
        
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        button.sizeToFit()
        
        customView = button
        
    }
    
}
